<?php

namespace IDock\Insurance\TPIC\Response;

use IDock\Http\Response;
use IDock\IDock\IDockEnums;
use IDock\Insurance\TPIC\Response\AllTPICResponse;
use IDock\Insurance\TPIC\TPICEnums;
use IDock\Printer\Premium\PremiumBIPrinter;
use IDock\Printer\Premium\PremiumCIPrinter;
use IDock\Printer\Premium\PremiumCoveragePrinter;
use IDock\Printer\Premium\PremiumFactorPrinter;
use IDock\Printer\Premium\PremiumInquiryPrinter;
use IDock\Printer\Premium\PremiumTaxPrinter;
use IDock\Printer\PremiumUnderwritingPrinter;
use IDock\Printer\VehicleModelPrinter;
use IDock\Printer\VehiclePrinter;

class UnderwritingResponse extends AllTPICResponse
{
    /*** @var PremiumUnderwritingPrinter $printer */
    public $printer = PremiumUnderwritingPrinter::class;
    public function printerInit() :Response
    {
        $premiumInquiryPrinter = new PremiumInquiryPrinter();
        $modelList =  [];
        $body = $this->getBody()['body'] ?? '';
        $riskList = $this->formatArray($body['risk'] ?? []);
        $biStatus = $ciStatus = '';
        $biTip = $ciTip = '';
        foreach ($riskList as $value){
            if($value['riskCode'] == 'BS'){
                $this->printer->biInquiryNo = $value['proposalNo'] ?? '';
                $biStatus = $value['underWriteInd'] ?? '';
                $biTip = $value['iLogInfo'] ?? '';
            }
            if($value['riskCode'] == 'BZ'){
                $this->printer->ciInquiryNo = $value['proposalNo'] ?? '';
                $ciStatus = $value['underWriteInd'] ?? '';
                $ciTip = $value['iLogInfo'] ?? '';
            }
        }
        $this->printer->statusCode = 'U3';
        if(!empty($biStatus) && !empty($ciStatus)){
            if(in_array($biStatus,[1,3,6]) && in_array($ciStatus,[1,3,6])){
                $this->printer->statusCode = 'U1';
            }
            if(in_array($biStatus,[2,4,7]) or in_array($ciStatus,[2,4,7])){
                $this->printer->statusCode = 'U4';
                if(!empty($ciTip)){
                    $this->printer->messageTip = '交强险提示：'.$ciTip."\r\n";
                }
                if(!empty($biTip)){
                    $this->printer->messageTip .= '商业险提示：'.$biTip;
                }

            }
        }else{
            $status = $ciStatus ?: $biStatus;
            if(in_array($status,[1,3,6])){
                $this->printer->statusCode = 'U1';
            }
            if(in_array($status,[2,4,7])){
                $this->printer->statusCode = 'U4';
                if(!empty($ciTip)){
                    $this->printer->messageTip = '交强险提示：'.$ciTip."\r\n";
                }
                if(!empty($biTip)){
                    $this->printer->messageTip .= '商业险提示：'.$biTip;
                }
            }
        }
        if(!empty($ciTip)){
            $this->printer->messageTip = '交强险提示：'.$ciTip."\r\n";
        }
        if(!empty($biTip)){
            $this->printer->messageTip .= '商业险提示：'.$biTip;
        }

        return $this;
    }

}
